package com.thb.base.dao.Impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.thb.base.dao.IAcadeDao;
import com.thb.base.model.Community;

@Repository
public class AcadeDaoImpl implements IAcadeDao {
	
	@Autowired
	private JdbcTemplate jTemplate;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public  List<Community> findAllSchool() {
		String sql = "select community_id,name,logo_img,type from community where type = 1";
		Object[] arg = new Object[] { };
		
		return jTemplate.query(sql, arg,new RowMapper() {
			public Object mapRow(ResultSet rs, int no) throws SQLException {

				return jsonMapper(rs, no);
			}
		});
	}

	private Community jsonMapper(ResultSet rs, int no) throws SQLException {

		Community vo = new Community();
		vo.setCommunityId(rs.getString("community_id"));
		vo.setName(rs.getString("name"));
		vo.setLogoImg(rs.getString("logo_img"));
		vo.setType(rs.getInt("type"));
	
		return vo;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public  List<Community> findAllOut() {
		String sql = "select community_id,name,logo_img,type from community where type = 2";
		Object[] arg = new Object[] { };
		
		return jTemplate.query(sql, arg,new RowMapper() {
			public Object mapRow(ResultSet rs, int no) throws SQLException {

				return jsonMapper(rs, no);
			}
		});
	}

}
